package smcms.service.sso.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import smcms.commons.api.entity.result.CommonsResult;
import smcms.service.sso.entity.StaffInfoReq;
import smcms.service.sso.entity.StaffInfoResp;
import smcms.service.sso.service.StaffService;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/StaffController")
public class StaffController {
    @Autowired
    private CommonsResult commonsResult;
    @Autowired
    private StaffService staffService;

    @PostMapping("/addCloudStaff")
    @PreAuthorize("hasAuthority('smcms-service-sso/addCloudStaff')")
    public CommonsResult addCloudStaff(@RequestBody StaffInfoReq req, HttpServletRequest request){
        CommonsResult commonsResult = staffService.addCloudStaff(req,request);
        return commonsResult;
    }

    @PostMapping("/queryCloudStaff")
    public CommonsResult queryCloudStaff(@RequestBody StaffInfoReq req){
        PageInfo<StaffInfoResp> staffInfoResps = staffService.queryCloudStaff(req);
        return commonsResult.success(staffInfoResps);
    }
    @PostMapping("/deleteStaff")
    public CommonsResult deleteStaff(@RequestBody List<String> accountList) {
        CommonsResult commonsResult = staffService.deleteStaff(accountList);
        return commonsResult;
    }

    @PostMapping("/updateStaff")
    public CommonsResult updateStaff(@RequestBody StaffInfoReq req) {
        CommonsResult commonsResult = staffService.updateStaff(req);
        return commonsResult;
    }
}
